package cn.vcjf.weapp.api.user.controller;


import org.springframework.web.bind.annotation.RequestMapping;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.ResponseBody;
import cn.vcjf.weapp.common.web.TableResult;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import cn.vcjf.weapp.api.user.entity.UserCash;
import cn.vcjf.weapp.api.user.service.UserCashService;

import org.springframework.stereotype.Controller;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhengzihang
 * @since 2018-09-25
 */
@Controller
@RequestMapping("/user/userCash")
public class UserCashController {
     @Resource
     private UserCashService  userCashService;

     @RequestMapping("/addUserCash")
     @ResponseBody
     public TableResult addUserCash(UserCash userCash){
         userCash.preInsert();
         boolean b = userCashService.insert(userCash);
         return TableResult.Result(b);
     }

     @RequestMapping("/updateUserCash")
     @ResponseBody
     public TableResult updateUserCash(UserCash userCash){
         userCash.preUpdate();
        boolean b = userCashService.updateById(userCash);
         return TableResult.Result(b);
     }

     @RequestMapping("/findUserCashOne")
     @ResponseBody
     public TableResult findUserCashOne(UserCash userCash){

        EntityWrapper<UserCash> wrapper = new EntityWrapper<UserCash>();

        if(userCash.getId()!=null){
            wrapper.eq("id",userCash.getId());
        }
        //Todo

        UserCash result = userCashService.selectOne(wrapper);

		return TableResult.OKResult(result);
     }

     @RequestMapping("/findUserCashList")
     @ResponseBody
     public TableResult findUserCashList(UserCash userCash){

        EntityWrapper<UserCash> wrapper = new EntityWrapper<UserCash>();

		if(userCash.getId()!=null){
            wrapper.eq("id",userCash.getId());
        }
        //Todo

        Page<UserCash> page = userCash.getPageInfo();

        page = userCashService.selectPage(page,wrapper);

		return TableResult.OKResult(page);

     }

     @RequestMapping("/deleteUserCash")
     @ResponseBody
     public TableResult deleteUserCash(UserCash userCash){
        userCash.preUpdate();
        boolean b = userCashService.deleteById(userCash.getId());
        return TableResult.Result(b);
     }

}
